import pymysql

conn = pymysql.connect(host="localhost", port=3306, user="root", password="root", database="test", charset="utf8")
cursor = conn.cursor()

sql = "insert into test (name) values (%s)"

try:
    for i in range(1000):
        cursor.execute(sql, (i,))
    conn.commit()
except Exception as e:
    conn.rollback()

cursor.close()
conn.close()

